package com.xiaoyu.lanling.feature.chat.viewholder

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.CallSuper
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.chat.model.message.ChatMessageReceiveSendBaseItem
import com.xiaoyu.lanling.media.image.ImageViewUtil.loadImage
import com.xiaoyu.lanling.view.UserAvatarDraweeView
import com.xiaoyu.lanling.view.text.UserNameTextView

abstract class ChatMessageBaseReceiveSendViewHolder<T : ChatMessageReceiveSendBaseItem> : ChatMessageBaseViewHolder<T>() {

    protected var mUserAvatar: UserAvatarDraweeView? = null
    protected var mUserDisplayName: UserNameTextView? = null

    protected abstract fun doCreateChildrenView(layoutInflater: LayoutInflater, parent: ViewGroup): View?

    override fun doCreateView(layoutInflater: LayoutInflater, parent: ViewGroup): View? {
        val view = doCreateChildrenView(layoutInflater, parent)
        mUserAvatar = view?.findViewById(R.id.chat_message_avatar)
        mUserDisplayName = view?.findViewById(R.id.chat_message_name)
        return view
    }

    @CallSuper
    override fun showData(position: Int, itemData: T) {
        mUserAvatar?.let {
            loadImage(it, itemData.avatarParam)
        }
        mUserAvatar?.allowJumpToUserPage(itemData.message.chatToken.chatId)
    }
}